package com.pipayshop.listener;
import com.pipayshop.config.OrderQueueConfig;
import com.pipayshop.service.PhysicalStoreOrderInfoService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues = OrderQueueConfig.STORE_DELAY_QUEUE)
public class PhysicalMessageListener {

    @Autowired
    private PhysicalStoreOrderInfoService physicalStoreOrderInfoService;

    /***
     * 监听消息
     * @param msg
     */
    @RabbitHandler
    public void msg(@Payload Object msg) {
        Message msg1 = (Message) msg;
        byte[] bodyBytes = msg1.getBody();
        String bodyString = new String(bodyBytes);
        // 假设需要移除空格或其他不必要的字符
        String content = bodyString.trim();
        String[] split = content.split("_");

        if (split[0].equals("store")) {
            physicalStoreOrderInfoService.failOrder(split[1]);
        }

    }

}
